<?php
    use yii\helpers\Html;
    use yii\helpers\Url;
    use yii\widgets\LinkPager;
?>
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">

            <div class="ibox">
                <div class="ibox-title">
                    <h5>权限列表</h5>
                </div>
                <div class="ibox-content">
                    <div class="form-group form-horizontal form-style">
                        <?php if($this->context->isAuth('admin-role-permission/permission-add')){?>
                        <a class="btn btn-primary" href="<?= Url::to('permission-add')?>">添加权限</a>
                        <?php }?>
                    </div>
                    <div class="form-group form-horizontal form-style">
                        <form method="get" action="">
                            <div class="row m-b">
                                <label class="col-sm-1 control-label">所属菜单</label>
                                <div class="col-sm-2">
                                    <select class="form-control" name="parent_id">
                                        <option value="">全部</option>
                                        <?php if(!empty($parent_rower)){foreach($parent_rower as $k => $v){?>
                                            <option value="<?=$k?>" <?= $parent_id == $k ? 'selected' : ''?>><?= $v;?></option>
                                        <?php }}?>
                                    </select>
                                </div>
                                <label class="col-sm-1 control-label">关键词</label>
                                <div class="col-sm-2">
                                    <input type="text" name="keywords" class="form-control" value="<?=$keywords?>" placeholder="输入名称">
                                </div>
                                <div class="col-sm-2">
                                    <button type="submit" class="btn  btn-primary ">搜索</button>
                                </div>
                            </div>
                        </form>
                    </div>
                    <table class="table table-striped table-bordered table-hover dataTables-example">
                        <tr class="tb-title">
                            <th class="text-center">ID</th>
                            <th class="text-center">所属菜单</th>
                            <th class="text-center">名称</th>
                            <th class="text-center">路由</th>
                            <th class="text-center">菜单码</th>
                            <th class="text-center">操作码</th>
                            <th class="text-center">状态</th>
                            <th class="text-center">创建时间</th>
                            <th class="text-center">操作</th>
                        </tr>
                        <?php if(!empty($list)) foreach($list as $val){ ?>
                        <tr align="center" data-id="<?= $val->id?>">
                            <td><?= $val->id ?></td>
                            <td><?= $val->parent_id ? $parent_rower[$val->parent_id]:'' ?></td>
                            <td><?= Html::encode($val->name) ?></td>
                            <td><?= Html::encode($val->url) ?></td>
                            <td><?= $val->menu_code ?></td>
                            <td><?= $val->btn_code ?></td>
                            <td>
                                <?php if($this->context->isAuth('admin-role-permission/permission-status-ajax-do')){?>
                                    <?= $val->status == 1?'<a href="javascript:;" class="btn btn-xs btn-primary ajax_action" data-status="0" tip="禁用" url="permission-status-ajax-do">正常</a>':'<a href="javascript:;" class="btn btn-xs btn-warning ajax_action" data-status="1" tip="启用" url="permission-status-ajax-do">禁用</a>' ?>
                                <?php }else{?>
                                    <?= $val->status == 1?'正常':'禁用' ?>
                                <?php }?>
                            </td>
                            <td><?= date('Y-m-d',$val->create_time) ?></td>
                            <td>
                                <?php if($this->context->isAuth('admin-role-permission/permission-edit')){?><a class="btn btn-xs btn-primary" href="<?=Url::to(['permission-edit','id'=>$val->id])?>">编辑</a>&nbsp;&nbsp;<?php }?>
                            </td>
                        </tr>
                        <?php }?>
                    </table>
                    <?php
                        echo LinkPager::widget([
                            'pagination' => $pagination,
                        ]);
                    ?>
                </div>
            </div>
        </div>
    </div>